package probability;

import java.util.ArrayList;

import basics.Vector;
import basics.VectorMatrix;

public abstract class ProbabilityDistribution {

	protected ArrayList<VectorMatrix> _params;

	public ProbabilityDistribution() {
		_params = new ArrayList<VectorMatrix>();
	}

	public ProbabilityDistribution(ArrayList<VectorMatrix> params) {
		_params = params;
	}

	// public List<VectorMatrix> getParams() {
	// return _params;
	// }

	public abstract double measure(Vector x);

	public VectorMatrix getParam(int i) {
		return _params.get(i);
	}

	public void setParam(int i, VectorMatrix vm) {
		_params.set(i, vm);
	}

	private static ArrayList<VectorMatrix> copy(ArrayList<VectorMatrix> params) {
		return (ArrayList<VectorMatrix>) params.clone();
	}

	public ArrayList<VectorMatrix> getParamsCopy() {
		// ArrayList<VectorMatrix> ar = new ArrayList<VectorMatrix>();
		return copy((ArrayList<VectorMatrix>) _params);
	}

	protected abstract ProbabilityDistribution newInstance();

	public ProbabilityDistribution clone() {
		ProbabilityDistribution pd = newInstance();
		pd._params.clear();
		pd._params.addAll(getParamsCopy());

		return pd;
	}

	public String toString() {
		StringBuilder str = new StringBuilder();
		for (VectorMatrix vm : _params) {
			str.append("[" + vm.toString() + "]\n");
		}
		return this.getClass().getName() + "\n" + str;
	}

	public String toStringCSV() {
		StringBuilder str = new StringBuilder();
		String append = ",";
		for (int i = 0; i < _params.size(); i++) {
			if (i == _params.size() - 1) {
				append = "\n";
			}
			str.append(_params.get(i).toString() + append);
		}
		return str.toString();
	}

	public abstract ProbabilityDistribution times(ProbabilityDistribution distribution);
}
